﻿namespace Forms
{
    using Forms.My;

    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    [DesignerGenerated]
    public class Main : Form
    {
        [AccessedThroughProperty("BMWKontenInternetabrufToolStripMenuItem")]
        private ToolStripMenuItem _BMWKontenInternetabrufToolStripMenuItem;

        [AccessedThroughProperty("DateiToolStripMenuItem")]
        private ToolStripMenuItem _DateiToolStripMenuItem;

        [AccessedThroughProperty("DatenEinlesenToolStripMenuItem")]
        private ToolStripMenuItem _DatenEinlesenToolStripMenuItem;

        [AccessedThroughProperty("DatensatzCount")]
        private Label _DatensatzCount;

        [AccessedThroughProperty("DatenschemaBMW")]
        private DatenschemaBMW _DatenschemaBMW;

        [AccessedThroughProperty("EasysToolStripMenuItem")]
        private ToolStripMenuItem _EasysToolStripMenuItem;

        [AccessedThroughProperty("EinstellungenToolStripMenuItem")]
        private ToolStripMenuItem _EinstellungenToolStripMenuItem;

        [AccessedThroughProperty("FinanzierungsartenToolStripMenuItem")]
        private ToolStripMenuItem _FinanzierungsartenToolStripMenuItem;

        [AccessedThroughProperty("InfoToolStripMenuItem")]
        private ToolStripMenuItem _InfoToolStripMenuItem;

        [AccessedThroughProperty("MenuStripMain")]
        private MenuStrip _MenuStripMain;

        [AccessedThroughProperty("PfadeToolStripMenuItem")]
        private ToolStripMenuItem _PfadeToolStripMenuItem;

        [AccessedThroughProperty("SchließenToolStripMenuItem")]
        private ToolStripMenuItem _SchließenToolStripMenuItem;

        [AccessedThroughProperty("SplitContainerMain")]
        private SplitContainer _SplitContainerMain;

        [AccessedThroughProperty("StatusBarMain")]
        private StatusStrip _StatusBarMain;

        [AccessedThroughProperty("StatusLabel")]
        private ToolStripStatusLabel _StatusLabel;

        [AccessedThroughProperty("StatusProgress")]
        private ToolStripProgressBar _StatusProgress;

        [AccessedThroughProperty("TreeViewNavigationMain")]
        private TreeView _TreeViewNavigationMain;


        public Session cs;

        public Main()
        {
            base.Load += new EventHandler(this.Main_Load);
            base.FormClosing += new FormClosingEventHandler(this.Main_FormClosing);
            this.cs = new Session();
            this.InitializeComponent();
        }

        private void BMWKontenInternetabrufToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmBMWDebKonten konten = new frmBMWDebKonten();
            konten.ShowDialog();
            konten.Close();
            konten.Dispose();
        }

        public void ClearTreeView()
        {
            TreeView treeViewNavigationMain = this.TreeViewNavigationMain;
            treeViewNavigationMain.BeginUpdate();
            treeViewNavigationMain.Nodes["F1"].Nodes.Clear();
            treeViewNavigationMain.Nodes["Konto"].Nodes.Clear();
            treeViewNavigationMain.Nodes["Auswertung"].Nodes.Clear();
            treeViewNavigationMain.EndUpdate();
            treeViewNavigationMain = null;
        }

        public void CreateAuswertungNode()
        {
            TreeView treeViewNavigationMain = this.TreeViewNavigationMain;
            treeViewNavigationMain.BeginUpdate();
            treeViewNavigationMain.Nodes["Auswertung"].Nodes.Clear();
            if (this.cs.AuswertungName == "")
            {
                this.cs.AuswertungName = DateAndTime.Now.ToString(@"dd\/MM");
            }
            treeViewNavigationMain.Nodes["Auswertung"].Nodes.Add(
                "Fakturierte mit Banksaldo - " + this.cs.AuswertungName).Tag = "AusChild";
            treeViewNavigationMain.Nodes["Auswertung"].Nodes.Add("Bestand ohne Banksaldo - " + this.cs.AuswertungName).
                Tag = "AusChild2";
            treeViewNavigationMain.EndUpdate();
            treeViewNavigationMain.ExpandAll();
            treeViewNavigationMain = null;
        }

        private void DatenEinlesenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Interaction.MsgBox(
                "Wollen Sie wirklich neue Daten einlesen? Die alte Auswertung wird gelöscht.",
                MsgBoxStyle.Question | MsgBoxStyle.YesNo,
                "Neue Daten einlesen") == MsgBoxResult.Yes)
            {
                this.HideAllSubForms();
                this.TreeViewNavigationMain.Enabled = false;
                this.MenuStripMain.Enabled = false;
                this.cs.BemerkungenSpeichernAuswertung();
                this.cs.DauerFAsSpeichern();
                this.cs.BemerkungenSpeichernAuswertungBestand();
                this.StatusProgress.Value = 0;
                this.StatusLabel.Text = "Lese Daten...";
                this.Refresh();
                this.cs.ClearData();
                this.ClearTreeView();
                this.FillTreeView();
                if (Directory.Exists(MySettings.MySettingsProperty.FilesPath))
                {
                    if (this.cs.ReadFiles(MySettings.MySettingsProperty.FilesPath))
                    {
                        if (MySettings.MySettingsProperty.DoBackup)
                        {
                            this.StatusProgress.Value = 0;
                            this.StatusLabel.Text = "Sichere Importdateien...";
                            this.cs.BackupFiles(
                                MySettings.MySettingsProperty.FilesPath, MySettings.MySettingsProperty.FilesBackupPath);
                        }
                        this.ClearTreeView();
                        this.FillTreeView();
                        this.StatusProgress.Value = 0;
                        this.StatusLabel.Text = "Erzeuge Auswertung...";
                        this.Refresh();
                        this.cs.SetCompareFile();
                        this.CreateAuswertungNode();
                        this.TreeViewNavigationMain.SelectedNode =
                            this.TreeViewNavigationMain.Nodes["Auswertung"].Nodes[0];
                        this.StatusProgress.Value = 0;
                        this.StatusLabel.Text = "Bereit!";
                        MyProject.Forms.frmAuswertung.ResetFilter();
                        MyProject.Forms.frmAuswertung.InitSums();
                    }
                }
                else
                {
                    Interaction.MsgBox(
                        "Der eingestellte Importpfad ist nicht vorhanden. Bitte korrigieren Sie die Pfadeinstellungen!",
                        MsgBoxStyle.Critical,
                        "Fehler");
                    MyProject.Forms.frmPfade.ShowDialog();
                }
                this.TreeViewNavigationMain.Enabled = true;
                this.MenuStripMain.Enabled = true;
                frmProtokoll protokoll = new frmProtokoll();
                protokoll.MessageText = this.cs.Zusammenfassung;
                protokoll.MessageProt = this.cs.LeseProtokoll;
                protokoll.MessageIcon = this.cs.ProtokollSymbol;
                protokoll.ShowDialog();
            }
        }


        public void FillTreeView()
        {
            TreeNode node;
            DataRow row4;
            string str2;
            object[] objArray;
            object[] objArray2;
            bool[] flagArray;
            TreeView treeViewNavigationMain = this.TreeViewNavigationMain;
            treeViewNavigationMain.BeginUpdate();
            TreeNode node2 = treeViewNavigationMain.Nodes["F1"].Nodes.Add("Fakturierte Fahrzeuge");
            node2.Name = "Fakturiert";
            node2.Tag = "F1";
            node2 = treeViewNavigationMain.Nodes["F1"].Nodes.Add("Bestandsfahrzeuge");
            node2.Name = "Bestand";
            node2.Tag = "Bestand";
            IEnumerator enumerator = this.cs.Table_F1Headers.Rows.GetEnumerator();

            try
            {

                while (enumerator.MoveNext())
                {
                    DataRow current = (DataRow)enumerator.Current;
                    object left = current["Typ"];
                    if (Operators.ConditionalCompareObjectEqual(left, "Fakturiert", false))
                    {
                        node2 = treeViewNavigationMain.Nodes["F1"].Nodes["Fakturiert"];
                    }
                    else
                    {
                        node2 = treeViewNavigationMain.Nodes["F1"];
                    }
                    objArray = new object[1];
                    row4 = current;
                    str2 = "Name";
                    objArray[0] = RuntimeHelpers.GetObjectValue(row4[str2]);
                    objArray2 = objArray;
                    flagArray = new bool[] { true };
                    if (flagArray[0])
                    {
                        row4[str2] = RuntimeHelpers.GetObjectValue(objArray2[0]);
                    }
                    node = (TreeNode)NewLateBinding.LateGet(node2.Nodes, null, "Add", objArray2, null, null, flagArray);
                    node.Tag = current["F1_Header_ID"].ToString();
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            string right = "";
            IEnumerator enumerator2 = this.cs.Table_BestandHeaders.Rows.GetEnumerator();

            try
            {

                while (enumerator2.MoveNext())
                {
                    DataRow row2 = (DataRow)enumerator2.Current;
                    node2 = treeViewNavigationMain.Nodes["F1"].Nodes["Bestand"];
                    object obj3 = row2["Typ"];
                    if (Operators.ConditionalCompareObjectEqual(obj3, "N", false))
                    {
                        right = "Neu";
                    }
                    else if (Operators.ConditionalCompareObjectEqual(obj3, "G", false))
                    {
                        right = "Gebraucht";
                    }
                    else if (Operators.ConditionalCompareObjectEqual(obj3, "V", false))
                    {
                        right = "Vorführ";
                    }
                    node =
                        (TreeNode)
                        NewLateBinding.LateGet(
                            node2.Nodes,
                            null,
                            "Add",
                            new object[]
                                { Operators.ConcatenateObject(Operators.ConcatenateObject(row2["Name"], " - "), right) },
                            null,
                            null,
                            null);
                    node.Tag = row2["Bestand_Header_ID"].ToString();
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            if (treeViewNavigationMain.Nodes["F1"].Nodes["Fakturiert"].Nodes.Count == 0)
            {
                treeViewNavigationMain.Nodes["F1"].Nodes["Fakturiert"].Remove();
            }
            if (treeViewNavigationMain.Nodes["F1"].Nodes["Bestand"].Nodes.Count == 0)
            {
                treeViewNavigationMain.Nodes["F1"].Nodes["Bestand"].Remove();
            }
            node2 = treeViewNavigationMain.Nodes["Konto"].Nodes.Add("BMW-Bank");
            node2.Name = "BMW";
            node2.Tag = "BMW";
            node2 = treeViewNavigationMain.Nodes["Konto"].Nodes.Add("Andere");
            node2.Name = "Andere";
            node2.Tag = "BMW";

            IEnumerator enumerator3 = this.cs.Table_BMWBankHeaders.Rows.GetEnumerator();
            try
            {

                while (enumerator3.MoveNext())
                {
                    DataRow row3 = (DataRow)enumerator3.Current;
                    object obj4 = row3["Typ"];
                    if (Operators.ConditionalCompareObjectEqual(obj4, "BMW", false))
                    {
                        node2 = treeViewNavigationMain.Nodes["Konto"].Nodes["BMW"];
                        node =
                            (TreeNode)
                            NewLateBinding.LateGet(
                                node2.Nodes,
                                null,
                                "Add",
                                new object[]
                                    {
                                        Operators.ConcatenateObject(
                                            Operators.ConcatenateObject(row3["Name"], " - "), row3["Deb_Kto_Nr"])
                                    },
                                null,
                                null,
                                null);
                        node.Tag = row3["BMW_Header_ID"].ToString();
                    }
                    else
                    {
                        node2 = treeViewNavigationMain.Nodes["Konto"].Nodes["Andere"];
                        objArray2 = new object[1];
                        row4 = row3;
                        str2 = "Name";
                        objArray2[0] = RuntimeHelpers.GetObjectValue(row4[str2]);
                        objArray = objArray2;
                        flagArray = new bool[] { true };
                        if (flagArray[0])
                        {
                            row4[str2] = RuntimeHelpers.GetObjectValue(objArray[0]);
                        }
                        node =
                            (TreeNode)NewLateBinding.LateGet(node2.Nodes, null, "Add", objArray, null, null, flagArray);
                        node.Tag = row3["BMW_Header_ID"].ToString();
                    }
                }
            }
            finally
            {
                if (enumerator3 is IDisposable)
                {
                    (enumerator3 as IDisposable).Dispose();
                }
            }
            if (treeViewNavigationMain.Nodes["Konto"].Nodes["BMW"].Nodes.Count == 0)
            {
                treeViewNavigationMain.Nodes["Konto"].Nodes["BMW"].Remove();
            }
            if (treeViewNavigationMain.Nodes["Konto"].Nodes["Andere"].Nodes.Count == 0)
            {
                treeViewNavigationMain.Nodes["Konto"].Nodes["Andere"].Remove();
            }
            treeViewNavigationMain.EndUpdate();
            treeViewNavigationMain.ExpandAll();
            treeViewNavigationMain = null;
            if (this.cs.AuswertungName != "")
            {
                this.CreateAuswertungNode();
            }
        }

        private void FinanzierungsartenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyProject.Forms.frmFA.ShowDialog(this);
        }

        public void HideAllSubForms()
        {
            IEnumerator enumerator = this.SplitContainerMain.Panel2.Controls.GetEnumerator();
            try
            {

                while (enumerator.MoveNext())
                {
                    ((Control)enumerator.Current).Hide();
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            this.Focus();
        }

        private void InfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyProject.Forms.frmSplashScreen.Show();
        }

        public void InitData(TableType Type)
        {
            this.InitData(Type, -1);
        }

        public void InitData(TableType Type, int HeaderID)
        {
            DataView view = new DataView();
            switch (Type)
            {
                case TableType.F1:
                    {
                        view.Table = this.cs.Table_F1Details;
                        view.RowFilter = "F1_Header_ID=" + HeaderID.ToString();
                        MyProject.Forms.frmF1.DataGridViewF1.DataSource = view;
                        this.DatensatzCount.Text = Conversions.ToString(MyProject.Forms.frmF1.DataGridViewF1.Rows.Count)
                                                   + " Datensätze";
                        DataRow[] rowArray = this.cs.Table_F1Headers.Select(
                            "F1_Header_ID='" + HeaderID.ToString() + "'");
                        if (rowArray.Length > 0)
                        {
                            MyProject.Forms.frmF1.txtFilename.Text = Conversions.ToString(rowArray[0]["Name"]);
                            MyProject.Forms.frmF1.txtLastChanged.Text =
                                Conversions.ToString(
                                    Operators.ConcatenateObject("zuletzt geändert am ", rowArray[0]["LastChanged"]));
                        }
                        break;
                    }
                case TableType.BMW:
                    {
                        view.Table = this.cs.Table_BMWBankDetails;
                        view.RowFilter = "BMW_Header_ID=" + HeaderID.ToString();
                        MyProject.Forms.frmBMW.DataGridViewBMW.DataSource = view;
                        decimal expression = new decimal();
                        try
                        {
                            expression =
                                Convert.ToDecimal(
                                    RuntimeHelpers.GetObjectValue(
                                        view.Table.Compute("Sum(Kredit_Saldo)", view.RowFilter)));
                        }
                        catch (Exception exception1)
                        {
                            ProjectData.SetProjectError(exception1);
                            Exception exception = exception1;
                            expression = new decimal();
                            ProjectData.ClearProjectError();
                        }
                        this.DatensatzCount.Text =
                            Conversions.ToString(MyProject.Forms.frmBMW.DataGridViewBMW.Rows.Count) + " Datensätze";
                        DataRow[] rowArray3 =
                            this.cs.Table_BMWBankHeaders.Select("BMW_Header_ID='" + HeaderID.ToString() + "'");
                        if (rowArray3.Length > 0)
                        {
                            MyProject.Forms.frmBMW.txtFilename.Text = Conversions.ToString(rowArray3[0]["Name"]);
                            MyProject.Forms.frmBMW.txtLastChanged.Text =
                                Conversions.ToString(
                                    Operators.ConcatenateObject("zuletzt geändert am ", rowArray3[0]["LastChanged"]));
                            MyProject.Forms.frmBMW.txtSaldo.Text = "    Saldo: "
                                                                   + Strings.Format(expression, "###,###,###,##0.00");
                        }
                        break;
                    }
                case TableType.Auswertung:
                    MyProject.Forms.frmAuswertung.FilterChange(HeaderID);
                    this.DatensatzCount.Text =
                        Conversions.ToString(MyProject.Forms.frmAuswertung.DataGridViewAuswertung.Rows.Count)
                        + " Datensätze";
                    break;

                case TableType.Bestand:
                    {
                        view.Table = this.cs.Table_BestandDetails;
                        view.RowFilter = "Bestand_Header_ID=" + HeaderID.ToString();
                        MyProject.Forms.frmBestand.DataGridViewBestand.DataSource = view;
                        this.DatensatzCount.Text =
                            Conversions.ToString(MyProject.Forms.frmBestand.DataGridViewBestand.Rows.Count)
                            + " Datensätze";
                        DataRow[] rowArray2 =
                            this.cs.Table_BestandHeaders.Select("Bestand_Header_ID='" + HeaderID.ToString() + "'");
                        if (rowArray2.Length > 0)
                        {
                            MyProject.Forms.frmBestand.txtFilename.Text = Conversions.ToString(rowArray2[0]["Name"]);
                            MyProject.Forms.frmBestand.txtLastChanged.Text =
                                Conversions.ToString(
                                    Operators.ConcatenateObject("zuletzt geändert am ", rowArray2[0]["LastChanged"]));
                        }
                        break;
                    }
                case TableType.BestandA:
                    MyProject.Forms.frmF1_Auswertung.FilterChange(HeaderID);
                    this.DatensatzCount.Text =
                        Conversions.ToString(MyProject.Forms.frmF1_Auswertung.DataGridViewF1A.Rows.Count)
                        + " Datensätze";
                    break;
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            TreeNode node = new TreeNode("Formel-1 Dateien");
            TreeNode node2 = new TreeNode("Kontoauszüge");
            TreeNode node3 = new TreeNode("Auswertung");
            TreeNode node4 = new TreeNode("Historie abgelöste Fahrzeuge");
            this.MenuStripMain = new MenuStrip();
            this.DateiToolStripMenuItem = new ToolStripMenuItem();
            this.DatenEinlesenToolStripMenuItem = new ToolStripMenuItem();
            this.SchließenToolStripMenuItem = new ToolStripMenuItem();
            this.EinstellungenToolStripMenuItem = new ToolStripMenuItem();
            this.PfadeToolStripMenuItem = new ToolStripMenuItem();
            this.FinanzierungsartenToolStripMenuItem = new ToolStripMenuItem();
            this.EasysToolStripMenuItem = new ToolStripMenuItem();
            this.BMWKontenInternetabrufToolStripMenuItem = new ToolStripMenuItem();
            this.InfoToolStripMenuItem = new ToolStripMenuItem();
            this.SplitContainerMain = new SplitContainer();
            this.TreeViewNavigationMain = new TreeView();
            this.StatusBarMain = new StatusStrip();
            this.StatusProgress = new ToolStripProgressBar();
            this.StatusLabel = new ToolStripStatusLabel();
            this.DatensatzCount = new Label();
            this.DatenschemaBMW = new DatenschemaBMW();
            this.MenuStripMain.SuspendLayout();
            this.SplitContainerMain.Panel1.SuspendLayout();
            this.SplitContainerMain.SuspendLayout();
            this.StatusBarMain.SuspendLayout();
            this.DatenschemaBMW.BeginInit();
            this.SuspendLayout();
            this.MenuStripMain.Items.AddRange(
                new ToolStripItem[]
                    { this.DateiToolStripMenuItem, this.EinstellungenToolStripMenuItem, this.InfoToolStripMenuItem });
            Point point = new Point(0, 0);
            this.MenuStripMain.Location = point;
            this.MenuStripMain.Name = "MenuStripMain";
            Size size = new Size(0x303, 0x18);
            this.MenuStripMain.Size = size;
            this.MenuStripMain.TabIndex = 0;
            this.MenuStripMain.Text = "MenuStrip1";
            this.DateiToolStripMenuItem.DropDownItems.AddRange(
                new ToolStripItem[] { this.DatenEinlesenToolStripMenuItem, this.SchließenToolStripMenuItem });
            this.DateiToolStripMenuItem.Name = "DateiToolStripMenuItem";
            size = new Size(0x2c, 20);
            this.DateiToolStripMenuItem.Size = size;
            this.DateiToolStripMenuItem.Text = "Datei";
            this.DatenEinlesenToolStripMenuItem.Name = "DatenEinlesenToolStripMenuItem";
            size = new Size(0x91, 0x16);
            this.DatenEinlesenToolStripMenuItem.Size = size;
            this.DatenEinlesenToolStripMenuItem.Text = "Daten einlesen";
            this.SchließenToolStripMenuItem.Name = "SchließenToolStripMenuItem";
            size = new Size(0x91, 0x16);
            this.SchließenToolStripMenuItem.Size = size;
            this.SchließenToolStripMenuItem.Text = "Schließen";
            this.EinstellungenToolStripMenuItem.DropDownItems.AddRange(
                new ToolStripItem[]
                    {
                        this.PfadeToolStripMenuItem, this.FinanzierungsartenToolStripMenuItem, this.EasysToolStripMenuItem
                        , this.BMWKontenInternetabrufToolStripMenuItem
                    });
            this.EinstellungenToolStripMenuItem.Name = "EinstellungenToolStripMenuItem";
            size = new Size(0x52, 20);
            this.EinstellungenToolStripMenuItem.Size = size;
            this.EinstellungenToolStripMenuItem.Text = "Einstellungen";
            this.PfadeToolStripMenuItem.Name = "PfadeToolStripMenuItem";
            size = new Size(0xc9, 0x16);
            this.PfadeToolStripMenuItem.Size = size;
            this.PfadeToolStripMenuItem.Text = "Allgemein";
            this.FinanzierungsartenToolStripMenuItem.Name = "FinanzierungsartenToolStripMenuItem";
            size = new Size(0xc9, 0x16);
            this.FinanzierungsartenToolStripMenuItem.Size = size;
            this.FinanzierungsartenToolStripMenuItem.Text = "Finanzierungsarten";
            this.EasysToolStripMenuItem.Name = "EasysToolStripMenuItem";
            size = new Size(0xc9, 0x16);
            this.EasysToolStripMenuItem.Size = size;
            this.EasysToolStripMenuItem.Text = "Easy-Archiv";
            this.BMWKontenInternetabrufToolStripMenuItem.Name = "BMWKontenInternetabrufToolStripMenuItem";
            size = new Size(0xc9, 0x16);
            this.BMWKontenInternetabrufToolStripMenuItem.Size = size;
            this.BMWKontenInternetabrufToolStripMenuItem.Text = "BMW-Konten Internetabruf";
            this.InfoToolStripMenuItem.Name = "InfoToolStripMenuItem";
            size = new Size(0x25, 20);
            this.InfoToolStripMenuItem.Size = size;
            this.InfoToolStripMenuItem.Text = "Info";
            this.SplitContainerMain.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom
                                             | AnchorStyles.Top;
            this.SplitContainerMain.FixedPanel = FixedPanel.Panel1;
            point = new Point(0, 0x18);
            this.SplitContainerMain.Location = point;
            this.SplitContainerMain.Name = "SplitContainerMain";
            this.SplitContainerMain.Panel1.Controls.Add(this.TreeViewNavigationMain);
            size = new Size(0x303, 0x1e8);
            this.SplitContainerMain.Size = size;
            this.SplitContainerMain.SplitterDistance = 0xd7;
            this.SplitContainerMain.TabIndex = 1;
            this.TreeViewNavigationMain.Dock = DockStyle.Fill;
            this.TreeViewNavigationMain.FullRowSelect = true;
            this.TreeViewNavigationMain.HideSelection = false;
            this.TreeViewNavigationMain.ItemHeight = 20;
            point = new Point(0, 0);
            this.TreeViewNavigationMain.Location = point;
            this.TreeViewNavigationMain.Name = "TreeViewNavigationMain";
            node.BackColor = SystemColors.ControlLight;
            node.Name = "F1";
            node.Tag = "F1P";
            node.Text = "Formel-1 Dateien";
            node2.BackColor = SystemColors.ControlLight;
            node2.Name = "Konto";
            node2.Tag = "KontoP";
            node2.Text = "Kontoauszüge";
            node3.BackColor = SystemColors.ControlLight;
            node3.Name = "Auswertung";
            node3.Tag = "Auswertung";
            node3.Text = "Auswertung";
            node4.BackColor = SystemColors.ControlLight;
            node4.Name = "Historie";
            node4.Tag = "Historie";
            node4.Text = "Historie abgelöste Fahrzeuge";
            this.TreeViewNavigationMain.Nodes.AddRange(new TreeNode[] { node, node2, node3, node4 });
            this.TreeViewNavigationMain.RightToLeft = RightToLeft.Yes;
            this.TreeViewNavigationMain.ShowLines = false;
            size = new Size(0xd7, 0x1e8);
            this.TreeViewNavigationMain.Size = size;
            this.TreeViewNavigationMain.TabIndex = 0;
            this.StatusBarMain.Items.AddRange(new ToolStripItem[] { this.StatusProgress, this.StatusLabel });
            point = new Point(0, 0x203);
            this.StatusBarMain.Location = point;
            this.StatusBarMain.Name = "StatusBarMain";
            size = new Size(0x303, 0x16);
            this.StatusBarMain.Size = size;
            this.StatusBarMain.TabIndex = 2;
            this.StatusBarMain.Text = "StatusBarMain";
            this.StatusProgress.Name = "StatusProgress";
            size = new Size(100, 0x10);
            this.StatusProgress.Size = size;
            this.StatusProgress.Step = 1;
            this.StatusLabel.Name = "StatusLabel";
            size = new Size(0x25, 0x11);
            this.StatusLabel.Size = size;
            this.StatusLabel.Text = "Bereit!";
            this.DatensatzCount.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.DatensatzCount.AutoSize = true;
            point = new Point(0x296, 520);
            this.DatensatzCount.Location = point;
            this.DatensatzCount.Name = "DatensatzCount";
            size = new Size(0, 13);
            this.DatensatzCount.Size = size;
            this.DatensatzCount.TabIndex = 3;
            this.DatensatzCount.TextAlign = ContentAlignment.MiddleRight;
            this.DatenschemaBMW.DataSetName = "DatenschemaBMW";
            this.DatenschemaBMW.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema;
            SizeF ef = new SizeF(6f, 13f);
            this.AutoScaleDimensions = ef;
            this.AutoScaleMode = AutoScaleMode.Font;
            size = new Size(0x303, 0x219);
            this.ClientSize = size;
            this.Controls.Add(this.DatensatzCount);
            this.Controls.Add(this.StatusBarMain);
            this.Controls.Add(this.SplitContainerMain);
            this.Controls.Add(this.MenuStripMain);
            this.MainMenuStrip = this.MenuStripMain;
            this.Name = "Main";
            this.Text = "Solvo - Fahrzeugfinanzierung und Management für BMW";
            this.MenuStripMain.ResumeLayout(false);
            this.MenuStripMain.PerformLayout();
            this.SplitContainerMain.Panel1.ResumeLayout(false);
            this.SplitContainerMain.ResumeLayout(false);
            this.StatusBarMain.ResumeLayout(false);
            this.StatusBarMain.PerformLayout();
            this.DatenschemaBMW.EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void InternetzugriffeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyProject.Forms.frmEasy.ShowDialog();
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.StatusLabel.Text = "Speichere...";
            this.Refresh();
            this.cs.BemerkungenSpeichernAuswertung();
            this.cs.BemerkungenSpeichernAuswertungBestand();
            this.cs.DauerFAsSpeichern();
            this.StatusLabel.Text = "Bereit!";
            this.cs.SessionSave();
        }

        private bool CheckIsLocked(string fileName)
        {
            bool locked = File.Exists(MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.locked");
            if (locked)
            {
                var info = new FileInfo(fileName);
                var diff = DateTime.Now.Subtract(info.LastWriteTime);
                if (diff.Minutes > 5)
                {
                    File.Move(
                        MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.locked",
                        MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.xml");
                    File.Delete(MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.locked");
                    locked = false;
                }
            }
            return locked;
        }

        private void Main_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
            if (CheckIsLocked(MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.locked"))
            {
                Interaction.MsgBox(
                    "Die Datenbankdatei ist gesperrt. Ein anderer Benutzer greift auf die Daten zu.\r\nPfad: "
                    + MySettings.MySettingsProperty.DatabasePath,
                    MsgBoxStyle.Exclamation,
                    "Datenbank ist gesperrt");
                this.cs.SessionClose();
            }
            else if (File.Exists(MySettings.MySettingsProperty.DatabasePath + @"\amDataBase.xml"))
            {
                this.cs.SessionLoad();
            }
            else if (MyProject.Forms.frmPfade.ShowDialog() == DialogResult.Retry)
            {
                this.cs.SessionSave();
                this.cs.SessionLoad();
            }
            frmF1 mf = MyProject.Forms.frmF1;
            mf.FormBorderStyle = FormBorderStyle.None;
            mf.TopLevel = false;
            mf.Dock = DockStyle.Fill;
            mf.Visible = false;
            mf = null;
            frmBMW frmBMW = MyProject.Forms.frmBMW;
            frmBMW.FormBorderStyle = FormBorderStyle.None;
            frmBMW.TopLevel = false;
            frmBMW.Dock = DockStyle.Fill;
            frmBMW.Visible = false;
            frmBMW = null;
            frmBMWKomplett frmBMWKomplett = MyProject.Forms.frmBMWKomplett;
            frmBMWKomplett.FormBorderStyle = FormBorderStyle.None;
            frmBMWKomplett.TopLevel = false;
            frmBMWKomplett.Dock = DockStyle.Fill;
            frmBMWKomplett.Visible = false;
            frmBMWKomplett = null;
            frmBestand frmBestand = MyProject.Forms.frmBestand;
            frmBestand.FormBorderStyle = FormBorderStyle.None;
            frmBestand.TopLevel = false;
            frmBestand.Dock = DockStyle.Fill;
            frmBestand.Visible = false;
            frmBestand = null;
            frmAuswertung frmAuswertung = MyProject.Forms.frmAuswertung;
            frmAuswertung.FormBorderStyle = FormBorderStyle.None;
            frmAuswertung.TopLevel = false;
            frmAuswertung.ResetFilter();
            frmAuswertung.Dock = DockStyle.Fill;
            frmAuswertung.Visible = false;
            frmAuswertung = null;
            frmF1_Auswertung auswertung2 = MyProject.Forms.frmF1_Auswertung;
            auswertung2.FormBorderStyle = FormBorderStyle.None;
            auswertung2.TopLevel = false;
            auswertung2.ResetFilter();
            auswertung2.Dock = DockStyle.Fill;
            auswertung2.Visible = false;
            auswertung2 = null;
            frmHistorie frmHistorie = MyProject.Forms.frmHistorie;
            frmHistorie.FormBorderStyle = FormBorderStyle.None;
            frmHistorie.TopLevel = false;
            frmHistorie.Dock = DockStyle.Fill;
            frmHistorie.Visible = false;
            frmHistorie = null;
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmF1);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmBMW);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmBMWKomplett);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmBestand);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmAuswertung);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmF1_Auswertung);
            this.SplitContainerMain.Panel2.Controls.Add(MyProject.Forms.frmHistorie);
            this.FillTreeView();
        }

        private void PfadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MyProject.Forms.frmPfade.ShowDialog() == DialogResult.Retry)
            {
                this.cs.SessionSave();
            }
        }

        internal void Reload()
        {
            this.HideAllSubForms();
            this.TreeViewNavigationMain.Enabled = false;
            this.MenuStripMain.Enabled = false;
            this.cs.BemerkungenSpeichernAuswertung();
            this.cs.DauerFAsSpeichern();
            this.cs.BemerkungenSpeichernAuswertungBestand();
            this.cs.ClearDataReload();
            this.ClearTreeView();
            this.FillTreeView();
            this.StatusProgress.Value = 0;
            this.StatusLabel.Text = "Lese Daten...";
            this.Refresh();
            this.StatusProgress.Value = 0;
            this.StatusLabel.Text = "Erzeuge Auswertung...";
            this.Refresh();
            this.cs.SetCompareFile();
            this.CreateAuswertungNode();
            this.TreeViewNavigationMain.SelectedNode = this.TreeViewNavigationMain.Nodes["Auswertung"].Nodes[0];
            this.StatusProgress.Value = 0;
            this.StatusLabel.Text = "Bereit!";
            MyProject.Forms.frmAuswertung.ResetFilter();
            MyProject.Forms.frmAuswertung.InitSums();
            this.TreeViewNavigationMain.Enabled = true;
            this.MenuStripMain.Enabled = true;
        }

        private void SchließenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TreeViewNavigationMain_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag.ToString() != "")
            {
                if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "BMW", false))
                {
                    this.HideAllSubForms();
                    MyProject.Forms.frmBMWKomplett.Show();
                    MyProject.Forms.frmHistorie.Show();
                }
                if (e.Node.Parent != null)
                {
                    this.HideAllSubForms();

                    switch (e.Node.Parent.Tag.ToString())
                    {
                        case "F1":
                            this.InitData(TableType.F1, (int)Conversions.ToLong(e.Node.Tag));
                            MyProject.Forms.frmF1.Show();
                            break;
                        case "Bestand":
                            this.InitData(TableType.Bestand, (int)Conversions.ToLong(e.Node.Tag));
                            this.HideAllSubForms();
                            MyProject.Forms.frmBestand.Show();
                            break;
                        case "BMW":
                            this.InitData(TableType.BMW, (int)Conversions.ToLong(e.Node.Tag));
                            this.HideAllSubForms();
                            MyProject.Forms.frmBMW.Show();
                            break;
                        case "Auswertung":
                            if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "AusChild", false))
                            {
                                this.InitData(TableType.Auswertung);
                                this.HideAllSubForms();
                                MyProject.Forms.frmAuswertung.Show();
                                MyProject.Forms.frmAuswertung.InitGridColors();
                            }
                            if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "AusChild2", false))
                            {
                                this.InitData(TableType.BestandA);
                                this.HideAllSubForms();
                                MyProject.Forms.frmF1_Auswertung.Show();
                            }
                            break;
                        case "Historie":

                            this.HideAllSubForms();
                            MyProject.Forms.frmHistorie.Show();

                            break;
                    }

                    #region old code

                    //if (Operators.ConditionalCompareObjectEqual(e.Node.Parent.Tag, "F1", false))
                    //{

                    //}
                    //if (Operators.ConditionalCompareObjectEqual(e.Node.Parent.Tag, "Bestand", false))
                    //{
                    //    this.InitData(TableType.Bestand, (int) Conversions.ToLong(e.Node.Tag));
                    //    this.HideAllSubForms();
                    //    MyProject.Forms.frmBestand.Show();
                    //}
                    //if (Operators.ConditionalCompareObjectEqual(e.Node.Parent.Tag, "BMW", false))
                    //{
                    //    this.InitData(TableType.BMW, (int) Conversions.ToLong(e.Node.Tag));
                    //    this.HideAllSubForms();
                    //    MyProject.Forms.frmBMW.Show();
                    //}
                    //    if (Operators.ConditionalCompareObjectEqual(e.Node.Parent.Tag, "Auswertung", false))
                    //    {
                    //        if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "AusChild", false))
                    //        {
                    //            this.InitData(TableType.Auswertung);
                    //            this.HideAllSubForms();
                    //            MyProject.Forms.frmAuswertung.Show();
                    //            MyProject.Forms.frmAuswertung.InitGridColors();
                    //        }
                    //        if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "AusChild2", false))
                    //        {
                    //            this.InitData(TableType.BestandA);
                    //            this.HideAllSubForms();
                    //            MyProject.Forms.frmF1_Auswertung.Show();
                    //        }
                    //    }
                    //}
                    //else if (Operators.ConditionalCompareObjectEqual(e.Node.Tag, "Historie", false))
                    //{
                    //    this.HideAllSubForms();
                    //    MyProject.Forms.frmHistorie.Show();

                    #endregion
                }
            }
        }

        private void TreeViewNavigationMain_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '@')
            {
                MyProject.Forms.frmInternalFunctions.ShowDialog();
            }
        }

        internal virtual ToolStripMenuItem BMWKontenInternetabrufToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._BMWKontenInternetabrufToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.BMWKontenInternetabrufToolStripMenuItem_Click);
                if (this._BMWKontenInternetabrufToolStripMenuItem != null)
                {
                    this._BMWKontenInternetabrufToolStripMenuItem.Click -= handler;
                }
                this._BMWKontenInternetabrufToolStripMenuItem = value;
                if (this._BMWKontenInternetabrufToolStripMenuItem != null)
                {
                    this._BMWKontenInternetabrufToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual ToolStripMenuItem DateiToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._DateiToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._DateiToolStripMenuItem = value;
            }
        }

        internal virtual ToolStripMenuItem DatenEinlesenToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._DatenEinlesenToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.DatenEinlesenToolStripMenuItem_Click);
                if (this._DatenEinlesenToolStripMenuItem != null)
                {
                    this._DatenEinlesenToolStripMenuItem.Click -= handler;
                }
                this._DatenEinlesenToolStripMenuItem = value;
                if (this._DatenEinlesenToolStripMenuItem != null)
                {
                    this._DatenEinlesenToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual Label DatensatzCount
        {
            [DebuggerNonUserCode]
            get
            {
                return this._DatensatzCount;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._DatensatzCount = value;
            }
        }

        internal virtual DatenschemaBMW DatenschemaBMW
        {
            [DebuggerNonUserCode]
            get
            {
                return this._DatenschemaBMW;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._DatenschemaBMW = value;
            }
        }

        internal virtual ToolStripMenuItem EasysToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._EasysToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.InternetzugriffeToolStripMenuItem_Click);
                if (this._EasysToolStripMenuItem != null)
                {
                    this._EasysToolStripMenuItem.Click -= handler;
                }
                this._EasysToolStripMenuItem = value;
                if (this._EasysToolStripMenuItem != null)
                {
                    this._EasysToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual ToolStripMenuItem EinstellungenToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._EinstellungenToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._EinstellungenToolStripMenuItem = value;
            }
        }

        internal virtual ToolStripMenuItem FinanzierungsartenToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._FinanzierungsartenToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.FinanzierungsartenToolStripMenuItem_Click);
                if (this._FinanzierungsartenToolStripMenuItem != null)
                {
                    this._FinanzierungsartenToolStripMenuItem.Click -= handler;
                }
                this._FinanzierungsartenToolStripMenuItem = value;
                if (this._FinanzierungsartenToolStripMenuItem != null)
                {
                    this._FinanzierungsartenToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual ToolStripMenuItem InfoToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._InfoToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.InfoToolStripMenuItem_Click);
                if (this._InfoToolStripMenuItem != null)
                {
                    this._InfoToolStripMenuItem.Click -= handler;
                }
                this._InfoToolStripMenuItem = value;
                if (this._InfoToolStripMenuItem != null)
                {
                    this._InfoToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual MenuStrip MenuStripMain
        {
            [DebuggerNonUserCode]
            get
            {
                return this._MenuStripMain;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._MenuStripMain = value;
            }
        }

        internal virtual ToolStripMenuItem PfadeToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._PfadeToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.PfadeToolStripMenuItem_Click);
                if (this._PfadeToolStripMenuItem != null)
                {
                    this._PfadeToolStripMenuItem.Click -= handler;
                }
                this._PfadeToolStripMenuItem = value;
                if (this._PfadeToolStripMenuItem != null)
                {
                    this._PfadeToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual ToolStripMenuItem SchließenToolStripMenuItem
        {
            [DebuggerNonUserCode]
            get
            {
                return this._SchließenToolStripMenuItem;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.SchließenToolStripMenuItem_Click);
                if (this._SchließenToolStripMenuItem != null)
                {
                    this._SchließenToolStripMenuItem.Click -= handler;
                }
                this._SchließenToolStripMenuItem = value;
                if (this._SchließenToolStripMenuItem != null)
                {
                    this._SchließenToolStripMenuItem.Click += handler;
                }
            }
        }

        internal virtual SplitContainer SplitContainerMain
        {
            [DebuggerNonUserCode]
            get
            {
                return this._SplitContainerMain;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._SplitContainerMain = value;
            }
        }

        internal virtual StatusStrip StatusBarMain
        {
            [DebuggerNonUserCode]
            get
            {
                return this._StatusBarMain;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._StatusBarMain = value;
            }
        }

        internal virtual ToolStripStatusLabel StatusLabel
        {
            [DebuggerNonUserCode]
            get
            {
                return this._StatusLabel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._StatusLabel = value;
            }
        }

        internal virtual ToolStripProgressBar StatusProgress
        {
            [DebuggerNonUserCode]
            get
            {
                return this._StatusProgress;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                this._StatusProgress = value;
            }
        }

        internal virtual TreeView TreeViewNavigationMain
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TreeViewNavigationMain;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            [DebuggerNonUserCode]
            set
            {
                KeyPressEventHandler handler = new KeyPressEventHandler(this.TreeViewNavigationMain_KeyPress);
                TreeViewEventHandler handler2 = new TreeViewEventHandler(this.TreeViewNavigationMain_AfterSelect);
                if (this._TreeViewNavigationMain != null)
                {
                    this._TreeViewNavigationMain.KeyPress -= handler;
                    this._TreeViewNavigationMain.AfterSelect -= handler2;
                }
                this._TreeViewNavigationMain = value;
                if (this._TreeViewNavigationMain != null)
                {
                    this._TreeViewNavigationMain.KeyPress += handler;
                    this._TreeViewNavigationMain.AfterSelect += handler2;
                }
            }
        }

        /// <summary>
        /// Tabellentyp
        /// </summary>
        public enum TableType
        {
            Auswertung = 3,

            Bestand = 4,

            BestandA = 5,

            BMW = 2,

            F1 = 1
        }
    }
}

